package hp.com.servlet.AddressServlet;

import hp.com.entity.Users;
import hp.com.service.AddressService;
import hp.com.service.impl.AddressServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/AddAddress")
public class AddAddressServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AddressService as = new AddressServiceImpl();
        int account = ((Users) req.getSession().getAttribute("userSession")).getId();
        String address= req.getParameter("address");
        String name = req.getParameter("Name");
        String phone = req.getParameter("Phone");
        try{
            as.AddAddress(account,address,name,phone);
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        resp.sendRedirect(req.getContextPath()+"/Address");
    }
}
